#include <func.h>

int main(int argc, char* argv[])
{
	int fd = open("result.log", O_RDWR | O_CREAT | O_TRUNC, 0666);
	if (fd == -1) {
		error(1, errno, "open result.log");
	}

	write(STDERR_FILENO, "first error message\n", 20);

	// 将STDERR_FILENO重定向到result.log 
	if (dup2(fd, STDERR_FILENO) == -1) {
		error(1, errno, "dup2(%d,%d)", fd, STDERR_FILENO);
	}

	write(STDERR_FILENO, "second error message\n", 21);
	
	close(fd);
	close(STDERR_FILENO);
    return 0;
}

